package com.medicine.hbp.ui;

import org.kymjs.kjframe.http.HttpParams;
import org.kymjs.kjframe.ui.BindView;

import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.GridView;

import com.medicine.hbp.adapter.BqianAdapter;
import com.medicine.hbp.base.BaseActivity;
import com.medicine.hbp.http.AppHttpCallBack;
import com.medicine.hbp.http.AppHttps;
import com.medicine.hbp.http.HttpInterface;
import com.medicine.hbp.mob.FindLabersVo;
import com.medicine.hbp.uitl.ToastUtil;
import com.medicine.hbp.R;
/**
 * 标签页面
 * @author Administrator
 *
 */
public class LabelSelectActivity extends BaseActivity {
	@BindView(id = R.id.grid_bqtype)
	public GridView grid_bqtype;
	public FindLabersVo results = null;
	private BqianAdapter adapter = null;

	@Override
	public void setRootView() {
		super.setRootView();
		setContentView(R.layout.activity_labelselect);
	}

	@Override
	public void initWidget() {
		super.initWidget();
		bqid=getIntent().getStringExtra("id");
		httpFindLabers();
		initTop();
	}

	@Override
	public void widgetClick(View v) {
		super.widgetClick(v);
	}

	/**
	 * 标签获取
	 *
	 * @param file
	 */
	private void httpFindLabers() {
		HttpParams params = new HttpParams();
		AppHttps.HttpPost(this, HttpInterface.FIND_LABERS, params,
				new AppHttpCallBack<FindLabersVo>(FindLabersVo.class, aty) {
					@Override
					public void onSuccess(FindLabersVo result) {
						if (result != null) {
							results = result;
							adapter = new BqianAdapter(aty, result.laberList,bqid);
							grid_bqtype.setAdapter(adapter);
						}
					}

					@Override
					public void onFailures(int errorCode, String errorMsg) {
						ToastUtil.showShort(aty, errorMsg);

					}
				});
	}
	String bq="";
	String bqid="";
	private void initTop() {
		TopView topview = (TopView) findViewById(R.id.topview);
		topview.setTitle("标签列表");
		topview.setTitleColor(getResources().getColor(R.color.black));
		topview.setLeftVisibility(View.GONE);
		topview.setLeftVisibilityExit(View.VISIBLE);
		topview.setRightVisibility(View.GONE);
		topview.setRightTxtVisibility(View.VISIBLE);
		topview.setRightTitle("完成");
		topview.setRightTitleColor(getResources().getColor(R.color.black));
		topview.setLeftImageResource(R.drawable.leftarrow);
		topview.setLeftOnClickExit(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		topview.setTextRightOnClick(new OnClickListener() {

			@Override
			public void onClick(View arg0) {

				for (int i = 0; i <adapter.getLaberVos().size(); i++) {
					if(adapter.getLaberVos().get(i).laderBoolean==true){
						bq+=adapter.getLaberVos().get(i).laberName+",";
						bqid+=adapter.getLaberVos().get(i).laberId+",";
					}
				}
				if(TextUtils.isEmpty(bq)){
					ToastUtil.showShort(aty, "你还没有选择标签");
					return;
				}
				Intent intent=new Intent();
				intent.putExtra("bq", bq.substring(0, bq.length()-1));
				intent.putExtra("bqid", bqid.substring(0, bqid.length()-1));
				setResult(RESULT_OK, intent);
				finish();
			}
		});
	}
}
